package com.base.cn.platform.os.controller.global;

import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.controller.cmmon.ApiBaseController;
import com.base.cn.platform.os.service.course.cou.CourseService;
import com.base.cn.platform.os.service.exam.paper.ExamPaperService;
import com.base.cn.platform.os.service.manage.op.article.OpArticleService;
import com.base.cn.platform.os.service.manage.teacher.SysTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/api/global")
public class AppGlobalSearchController extends ApiBaseController {

    @Autowired
    private CourseService courseService;
    @Autowired
    private OpArticleService articleService;
    @Autowired
    private ExamPaperService examPaperService;
    @Autowired
    private SysTeacherService sysTeacherService;


    @RequestMapping("/globalSearch")
    public Map<String, Object> queryGroomDataList(@RequestParam(value = "userId", required = false, defaultValue = "0") BigDecimal userId, @RequestParam("overallValue") String overallValue) {
        Map<String, Object> params = new HashMap<>();
        params.put("courseNames", overallValue);
        List<Map<String, Object>> courseList = courseService.findCourseList(params, true, false, false, true);
        params.put("teacherNames", overallValue);
        List<Map<String, Object>> teacherList = sysTeacherService.findSysTeacherList(params, false, false, false, false, false);
        params.put("articleNames", overallValue);
        List<Map<String, Object>> articleList = articleService.findOpArticleList(params);
        params.put("paperNames", overallValue);
        params.put("userId", userId);
        params.put("examBuyStatusData", true);
        params.put("subjectData",true);
        params.put("newestData",true);
        params.put("status", 1);
        params.put("useType", 1);
        List<Map<String, Object>> examPaperList = examPaperService.findExamPaperList(params);
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("courseList", courseList);
        dataMap.put("teacherList", teacherList);
        dataMap.put("articleList", articleList);
        dataMap.put("examPaperList", examPaperList);
        return ResultUtil.SUCCESS(dataMap);
    }

}
